﻿using Volo.Abp.DependencyInjection;
using Volo.Abp.EventBus.Local;

namespace EventBus.Models
{
    public class MyService : ITransientDependency
    {
        private readonly ILocalEventBus _localEventBus;

        public MyService(ILocalEventBus localEventBus)
        {
            _localEventBus = localEventBus;
        }

        public virtual async Task ChangeStockCountAsync(Guid productId, int newCount)
        {
            //TODO: IMPLEMENT YOUR LOGIC...

            //PUBLISH THE EVENT
            await _localEventBus.PublishAsync(
                new StockCountChangedEvent
                {
                    ProductId = productId,
                    NewCount = newCount
                }
            );
            await _localEventBus.PublishAsync(
               new InStockCountChangedEvent
               {
                   ProductId = productId,
                   NewCount = newCount
               }
           );
        }
    }

    public class StockCountChangedEvent
    {
        public Guid ProductId { get; set; }

        public int NewCount { get; set; }
    }

    public class InStockCountChangedEvent
    {
        public Guid ProductId { get; set; }

        public int NewCount { get; set; }
    }
}
